package com.nondo.dean.pay.producer.service;

import java.util.List;

import com.nondo.dean.pay.constant.PayConstant;
import com.nondo.dean.pay.domain.PayChannel;
import com.nondo.dean.pay.domain.PayChannelExample;
import com.nondo.dean.pay.mapper.PayChannelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import com.nondo.dean.pay.constant.PayConstant;
import com.nondo.dean.pay.domain.PayChannel;
import com.nondo.dean.pay.domain.PayChannelExample;
import com.nondo.dean.pay.mapper.PayChannelMapper;

/**
 * @Description:
 * @author zhaolijin
 * @date 2018-02-07
 * @version V1.0
 * @Copyright: www.luobole.com
 */
@Component
public class PayChannelService {

    @Autowired
    private PayChannelMapper payChannelMapper;

    /**
     * 
     * @param channelId
     * @param mchId
     * @return
     */
    public PayChannel selectPayChannel(String channelId, String mchId) {
        PayChannelExample example = new PayChannelExample();
        PayChannelExample.Criteria criteria = example.createCriteria();
        criteria.andChannelIdEqualTo(channelId);
        criteria.andMchIdEqualTo(mchId);
        List<PayChannel> payChannelList = payChannelMapper.selectByExample(example);
        if(CollectionUtils.isEmpty(payChannelList)) return null;
        return payChannelList.get(0);
    }
    
    public List<PayChannel> getPayChannelList(String mchId) {
    	PayChannelExample example = new PayChannelExample();
        PayChannelExample.Criteria criteria = example.createCriteria();
        criteria.andMchIdEqualTo(mchId);
        criteria.andStateEqualTo(PayConstant.PAY_CHANNEL_STATE_ENABLE);
        List<PayChannel> payChannelList = payChannelMapper.selectByExample(example);
        if(CollectionUtils.isEmpty(payChannelList)) return null;
		return payChannelList;
    }

}
